package homework;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Test05 {
	//作业：对sort.txt进行排序
	public static void main(String[] args) throws IOException {
		File beforeSort = new File("D:\\FileTest\\sort.txt");
		File afterSort = new File("D:\\FileTest\\sorted.txt");
		Map<Integer,String> map=new HashMap<>();
		BufferedReader br = new BufferedReader(new FileReader(beforeSort));
		String line="";
		ArrayList<String> textLine = new ArrayList<>();
		while((line=br.readLine())!=null){
			if(line.length()>0)textLine.add(line);
		}
		br.close();
		System.out.println(textLine);
		
		Collections.sort(textLine);
		System.out.println(textLine);
		
		FileWriter fw=new FileWriter(afterSort);
		for(String ls:textLine){
			fw.write(ls);
			fw.write("\n");
		}
		fw.close();
	}
}
